/*
 * 类名称:AddressCityController.java
 * 包名称:com.lht.controller
 *
 * 修改履历:
 *     日期                       修正者        主要内容
 *     2019-09-30 17:02:56        ZhengZhanWu     初版做成
 */
package com.lht.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lht.admin.annotation.SysLog;
import com.lht.admin.constants.DataValidConstant;
import com.lht.admin.entity.AddressCityEntity;
import com.lht.admin.service.AddressCityService;
import com.lht.admin.utils.PageUtils;
import com.lht.admin.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 城市表Controller
 *
 * @author ZhengZhanWu
 * @date 2019-09-30 17:02:56
 */
@RestController
@RequestMapping("addresscity")
public class AddressCityController extends AbstractController {
    @Autowired
    private AddressCityService addressCityService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return R
     */
    @RequestMapping("/queryAll")
    @RequiresPermissions("addresscity:list")
    public R queryAll(@RequestParam Map<String, Object> params) {
        params.put("isDelete", DataValidConstant.IS_DELETE_FALSE_STR);
        List<AddressCityEntity> list = addressCityService.queryAll(params);

        return R.ok().put("list", list);
    }

    /**
     * 分页查询城市表
     *
     * @param params 查询参数
     * @return R
     */
    @RequestMapping("/list")
    @RequiresPermissions("addresscity:list")
    public R list(@RequestParam Map<String, Object> params) {
        params.put("isDelete", DataValidConstant.IS_DELETE_FALSE_STR);
        Page page = addressCityService.queryPage(params);
        PageUtils pageUtil = new PageUtils(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
        return R.ok().put("page", pageUtil);
    }

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return R
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("addresscity:info")
    public R info(@PathVariable("id") Long id) {
        AddressCityEntity addressCity = addressCityService.getById(id);

        return R.ok().put("addressCity", addressCity);
    }

    /**
     * 新增城市表
     *
     * @param addressCity addressCity
     * @return R
     */
    @SysLog("新增城市表")
    @PostMapping("/save")
    @RequiresPermissions("addresscity:save")
    public R save(@RequestBody AddressCityEntity addressCity) {
        addressCityService.add(addressCity);

        return R.ok();
    }

    /**
     * 修改城市表
     *
     * @param addressCity addressCity
     * @return R
     */
    @SysLog("修改城市表")
    @PostMapping("/update")
    @RequiresPermissions("addresscity:update")
    public R update(@RequestBody AddressCityEntity addressCity) {

        addressCityService.update(addressCity);

        return R.ok();
    }

    /**
     * 根据主键删除城市表
     *
     * @param ids ids
     * @return R
     */
    @SysLog("删除城市表")
    @PostMapping("/delete")
    @RequiresPermissions("addresscity:delete")
    public R delete(@RequestBody Long[] ids) {
        addressCityService.deleteBatch(ids);

        return R.ok();
    }
}
